{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "is_executing": true
    }
   },
   "source": [
    "# def find_largest_element(l):\n",
    "#     if not isinstance(l,list):\n",
    "#         print('input is not type of list')\n",
    "#         return\n",
    "#     if len(l) == 0:\n",
    "#         print('empty input')\n",
    "#         return\n",
    "#     largest_element = l[0]\n",
    "#     for item in l:\n",
    "#         if item > largest_element:\n",
    "#             largest_element = item\n",
    "#     print('larget element is:{}'.format(largest_element))\n",
    "# find_largest_element([1, 1,-3, 2, 0])\n",
    "\n",
    "# 函数嵌套\n",
    "# def factorial(input):\n",
    "#     if not isinstance(input,int):\n",
    "#         raise Exception('input must be an integer.')\n",
    "#     if input < 0:\n",
    "#         raise Exception('input must be positive.')\n",
    "#     def inter_factorial(input):\n",
    "#         if input <= 1:\n",
    "#             return 1\n",
    "#         return input*inter_factorial(input-1)\n",
    "#     return inter_factorial(input)\n",
    "# print(factorial(5))\n",
    "\n",
    "# 全局变量、局部变量\n",
    "# def outer():\n",
    "#     x = \"local\"\n",
    "#     def inner():\n",
    "#         x = 'nonlocal' # 这里的x是inner这个函数的局部变量\n",
    "#         print(\"inner:\", x)\n",
    "#     inner()\n",
    "#     print(\"outer:\", x)\n",
    "# outer()\n",
    "# 闭包 (返回一个函数)\n",
    "# def nth_power(exponent):\n",
    "#     def exponent_of(base):\n",
    "#         return base ** exponent\n",
    "#     return exponent_of\n",
    "# square = nth_power(2)\n",
    "# cube = nth_power(3)\n",
    "# print(square(2))\n",
    "# print(cube(2))\n",
    "# # 纯函数\n",
    "# def multiply_2_pure(l):\n",
    "#     new_list = []\n",
    "#     for item in l:\n",
    "#         new_list.append(item * 2)\n",
    "#     return new_list\n",
    "l = [1, 2, 3, 4, 5]\n",
    "new_list = map(lambda x: x * 2, l)\n",
    "print(new_list)"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-10T08:35:52.101489Z",
     "start_time": "2025-10-10T08:35:52.100123Z"
    }
   },
   "cell_type": "code",
   "source": "",
   "id": "b613bada6000204e",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "5c7bd02a79028f94"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
